package com.example.administrator.demoa;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;

class StuAdapter extends BaseAdapter{


    private Context context;
    private ArrayList<Student> students=new ArrayList<>();

    public StuAdapter(Context context, ArrayList<Student> students) {
        this.context = context;
        this.students = students;
    }
    @Override
    public int getCount() {
        return students.size();
    }

    @Override
    public Object getItem(int i) {
        return students.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if(view==null) {
            ViewHolder holder=new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.activity_my, viewGroup,false);
             holder.stuno=view.findViewById(R.id.stu_stuno);
            holder.name=view.findViewById(R.id.stu_name);
            holder.age=view.findViewById(R.id.stu_age);
            view.setTag(holder);
        }
        ViewHolder holder=(ViewHolder) view.getTag();
        holder.stuno.setText(students.get(i).getStuno());
        holder.name.setText(students.get(i).getName());
        holder.age.setText(String.valueOf(students.get(i).getAge()));
        return view;
    }
}
